<?php
require_once 'Zend/Date.php';

/**
 * dateHelper
 * @author    Soochow University
 * @version   1.0
 * @exclude   作  成  日：2011/04/07
 */
class dateHelper{

    /**
     * 日期+天数
     * @param   string  $date   日期
     * @param   string  $count  日数
     * @return
     */
    public static function addDate($date, $count){
        $check = (new ZEND_DATE($date));
        $check->add($count,Zend_Date::DAY);
        return date("Y/m/d",$check->toValue());
    }

    /**
     * 日期加小时
     * @param string  $date
     * @param integer $hour
     * @return string 日时
     */
    public static function addHour($date, $hour){
        $check = (new ZEND_DATE($date));
        $check->add($hour,Zend_Date::HOUR);
        return date("Y/m/d H:i:s",$check->toValue());
    }

    /**
     * 今天日期
     * @return string 日期
     */
    public static function getToday(){
        return date("Y/m/d");

    }

    /**
     * 现在时刻
     * @return 时刻
     */
    public static function getCurrentTime(){
        return date("Y/m/d H:i:s");
    }

    /**
     * 現在の時刻を取得
     * @return 時刻
     */
    public static function getDate(){
         return new Zend_Date();
    }

    /**
     * 变换指定格式日期
     * @param  string $date
     * @return 文字列
     */
    public static function toDateString($date){
        return date("Y/m/d H:i:s", strtotime($date));

    }

     
    /**
     * 第二天
     * @param  string $date
     * @return 日期
     */
    public static function getNextDay($date){

        return $date->add(1, Zend_Date::DAY);

    }
    

     /**
      * 日期比较
      * compare
      * @param string $startDate
      * @param string $endDate
      * @return number
      */
     public static function compare($startDate,$endDate) {
        $start=  strtotime($startDate);
        $end= strtotime($endDate);
        if($start>$end) {
            return 1;
        }else if($start==$end) {
            return 0;
        }else if ($start<$end) {
            return -1;
        }else {
            return 2;
        }
     }
     
    /**
     * 日期检查
     * @param  string $date
     * @return boolean型
     */
    public static function isDate($date){
        $check = (new ZEND_DATE());
        return $check->isDate($date);
    }

    
    /**
     * 小时数组
     * @return array
     */
    public static function getHoursForDropDownlist(){
        $arrHours=array("00","01","02","03","04","05","06","07","08",
                        "09","10","11","12","13","14","15",
                        "16","17","18","19","20","21","22","23");
        return $arrHours;
    }

    /**
     * 月数组
     * @return array
     */
    public static function getMonthsForDropDownlist(){
         $arrMonths=array("01","02","03","04","05","06","07",
                          "08","09","10","11","12",);
         return $arrMonths;
    }

    /**
     * 年数组
     * @return array
     */
    public static function getYearsForDropDownlist($startYears="1900",$endYears="2100",$sort=null){
        $arrYears = array();
        if($sort == null){
            for($i = $startYears; $i <= $endYears; $i++){
                $arrYears[] = $i;
            }
        }else{
            for($i = $endYears; $i >= $startYears; $i--){
                $arrYears[] = $i;
            }
        }
        return $arrYears;
    }

    /**
     * 分钟数组
     * @return array
     */
    public static function getMinutes(){
         $arrMinutes=array("00","01","02","03","04","05","06","07","08","09","10",
                           "11","12","13","14","15","16","17","18","19","20","21",
                           "22","23","24","25","26","27","28","29","30","31","32",
                           "33","34","35","36","37","38","39","40","41","42","43",
                           "44","45","46","47","48","49","50","51","52","53","54",
                           "55","56","57","58","59");
         return $arrMinutes;
    }

    /**
     * 取得该月天数
     * @param date $day
     */
    public static function getMonthDays($day) {
        if(empty($day)){
            return false;
        }
        $year = substr($day, 0,4);
        $month = substr($day, 5,2);
        return date("t", mktime(0, 0, 0, $month, 1, $year));
    }
    
    /**
     * 日期减法
     * @param date $dateFrom
     * @param date $dateTo
     */
    public static function dateSubDate($dateFrom, $dateTo){
        return (strtotime($dateTo) - strtotime($dateFrom))/86400;
    }
}

